#include <bits/stdc++.h>
using namespace std;
int a[25][100010],v[25][100010],d[25][100010],p[25][1000010];
int main(){
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    ios::sync_with_stdio(false);
    int t;
    cin>>t;
    int n[25],m[25],l[25],V[25];
    for(int i=1; i<=t; i++)
    {
        cin>>n[i]>>m[i]>>l[i]>>V[i];
        for(int j=1; j<=n[i]; j++)
        cin>>d[i][j]>>v[i][j]>>a[i][j];
        for(int j=1; j<=m[i]; j++)
        cin>>p[i][j];
    }
    int f2=1,f3=1;
    for(int i=1; i<=t; i++)
    {
        if(a[t][1]!=0)
            f2=0;
        if(a[t][1]<0)
            f3=0;
    }
    if(f2==1)
    {
        for(int i=1; i<=t; i++)
        {
            int ans1=0,ans2=1;
            for(int j=1; j<=n[i]; j++)
            {
                if(d[i][j]>p[i][m[i]])
                    continue;
                if(v[i][j]>V[i]&&d[i][j]<=l[i]&&v[i][j]>0)
                ans1++;
            }
            if(ans1!=0)
            cout<<ans1<<" "<<m[i]-ans2<<endl;
            else
            cout<<ans1<<" "<<m[i]<<endl;
        }
        return 0;
    }
    else if(f3==1)
    {
        for(int i=1; i<=t; i++)
        {
            int ans1=0,ans2=1;
            for(int j=1; j<=n[i]; j++)
            {
                if(d[i][j]>p[i][m[i]]) continue;
                if(sqrt(v[i][j]*v[i][j]+2*a[i][j]*(p[i][m[i]]-d[i][j]))>V[i])
                ans1++;
            }
            if(ans1!=0)
            cout<<ans1<<" "<<m[i]-ans2<<endl;
            else
            cout<<ans1<<" "<<m[i]<<endl;
        }
    }
    return 0;
}
